package com.ky.serialport.sensor;

import com.ky.serialport.bean.ComBean;

import static com.ky.serialport.utils.RandomUtils.myRandom;

/**
 * 转速
 */
public class ZhuanSuDataBean {

    public int signal; //信号值
    public int power; //电量值
    public long time; //数据包时间
    public float zhuanSuVel; //转速
    public int type = -1;
    public int index = -1;
    public ComBean comBean;

    public ZhuanSuDataBean() {
    }

    public ZhuanSuDataBean(ComBean comBean) {
        caculate(comBean.recData);
        time = comBean.recTime;
        this.comBean = comBean;
    }

    public ZhuanSuDataBean(byte[] recData) {
        caculate(recData);
        time = System.currentTimeMillis();
    }

    public ZhuanSuDataBean caculate(ComBean comBean){
        time = comBean.recTime;
        return caculate(comBean.recData);
    }

    public ZhuanSuDataBean caculate(byte[] buffer) {
        // TODO: 2020/1/3 解析数据
//        signal = MyFunc.getSignal(buffer[20]); //测试信号
//        power = MyFunc.getPower(buffer[18], buffer[19]);//电量
//        zhuanSuVel = MyFunc.twoByte2IntNoSign(buffer[14],buffer[15])/10f;
        type = buffer[9];
        index = buffer[10];
        return this;
    }

    public ZhuanSuDataBean test(int index){
        time = System.currentTimeMillis();
        signal = 200;
        power = 300 + myRandom.nextInt(120);
        zhuanSuVel =  myRandom.nextInt(20) + 20;
        return this;
    }

}
